package com.wngbms.feigndemo.controller;

import com.wngbms.feigndemo.api.UserService;
import com.wngbms.feigndemo.feign.LoginClient;
import com.wngbms.feigndemo.feign.LoginClientNative;
import feign.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Map;

@Slf4j
@RestController
public class Trigger {

    @Autowired
    UserService userService;
    @Autowired
    LoginClientNative loginClientNative;
    @Autowired
    LoginClient loginClient;

    @GetMapping("/trigger")
    public String trigger() {
        String notifyUser = userService.notifyUser("u1", "e12");
        log.info("{}", notifyUser);
        return "success";
    }

    @GetMapping("/testLoginNative")
    public String loginNative() {
        LoginController.LoginReq req = new LoginController.LoginReq();
        req.setUsername("wngbms");
        req.setPassword("password");

        Response response = loginClientNative.login(req);
        Map<String, Collection<String>> headers = response.headers();
        Response.Body body = response.body();

        return "success";
    }

    @GetMapping("/testLogin")
    public String login() {
        LoginController.LoginReq req = new LoginController.LoginReq();
        req.setUsername("wngbms");
        req.setPassword("password");

        LoginController.LoginResp login = loginClient.login(req);

        return "success";
    }

}
